package com.lanou3g.dllo.baidumusic.main.playerdetail;

import android.view.View;
import android.widget.ImageView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou3g.dllo.baidumusic.R;
import com.lanou3g.dllo.baidumusic.base.BaseFragment;
import com.lanou3g.dllo.baidumusic.main.playmusic.SongPlayBean;
import com.lanou3g.dllo.baidumusic.tools.SingleVolley;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by dllo on 16/7/1.
 */

public class SingerPhotoFragment extends BaseFragment{
    private ImageView singerPhoto;

    @Override
    public int setLayout() {
        EventBus.getDefault().register(this);
        return R.layout.fragment_singerphoto;
    }

    @Override
    public void initView(View view) {
        singerPhoto = (ImageView) view.findViewById(R.id.singerphoto_iv);
    }

    @Override
    public void initData() {

        // 获取主页面传过来的图片
        if (getActivity().getIntent().getSerializableExtra("playDetailBean") != null) {
            PlayDetailBean bean = (PlayDetailBean) getActivity().getIntent().getSerializableExtra("playDetailBean");
            String imgUrl = bean.getImgUrl();
            SingleVolley.getSingleVolley(context).getImageLoader().get(imgUrl, ImageLoader.getImageListener
                    (singerPhoto,R.mipmap.view_loading,R.mipmap.view_loading));
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getPhoto(SongPlayBean songPlayBean) {
        SingleVolley.getSingleVolley(context).getImageLoader().get(songPlayBean.getSonginfo().getPic_premium(),
                ImageLoader.getImageListener(singerPhoto,R.mipmap.view_loading,R.mipmap.view_loading));
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
